home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_05 / plauger / ios < prev    next >
Text File  |  1994-03-08  |  4KB  |  157 lines

  1.  
  2. ------------- Listing 1: The header <ios> ---------------------
  3.  
  4. // ios standard header
  5. #ifndef _IOS_
  6. #define _IOS_
  7. #include <exception>
  8. class ostream;
  9. class streambuf;
  10.         // class ios
  11. class ios {
  12. public:
  13.             // class failure
  14.     class failure : public xmsg {
  15.     public:
  16.         failure(const char *_X = 0, const char *_Y = 0,
  17.             const char *_Z = 0);
  18.             : xmsg(_X, _Y, _Z) {};
  19.         virtual ~failure();
  20.     };
  21.     enum _Fmtflags {skipws = 0x0001, unitbuf = 0x0002,
  22.         uppercase = 0x0004, showbase = 0x0008,
  23.         showpoint = 0x0010, showpos = 0x0020,
  24.         left = 0x0040, right = 0x0080, internal = 0x0100,
  25.         dec = 0x0200, oct = 0x0400, hex = 0x0800,
  26.         scientific = 0x1000, fixed = 0x2000,
  27.         adjustfield = 0x01c0, basefield = 0x0e00,
  28.         floatfield = 0x3000, _Fmtmask = 0x3fff, _Fmtzero = 0};
  29.     enum _Iostate {goodbit = 0x0, eofbit = 0x1,
  30.         failbit = 0x2, badbit = 0x4, _Statmask = 0x7};
  31.     enum _Openmode {in = 0x01, out = 0x02, ate = 0x04,
  32.         app = 0x08, trunc = 0x10, binary = 0x20};
  33.     enum seekdir {beg = 0, cur = 1, end = 2};
  34.     _BITMASK(_Fmtflags, fmtflags);
  35.     _BITMASK(_Iostate, iostate);
  36.     _BITMASK(_Openmode, openmode);
  37.     typedef int io_state, open_mode, seek_dir;
  38.             // class Init
  39.     class Init {
  40.     public:
  41.         Init();
  42.         ~Init();
  43.     private:
  44.         static int _Init_cnt;
  45.         };
  46.             // class _Iosarray
  47.     class _Iosarray {
  48.     public:
  49.         _Iosarray(int _Idx, _Iosarray *_Link = 0)
  50.             : _Next(_Link), _Index(_Idx), _Lo(0), _Vp(0) {}
  51.         _Iosarray *_Next;
  52.         int _Index;
  53.         long _Lo;
  54.         void *_Vp;
  55.         };
  56.     ios(streambuf *_S)
  57.         {init(_S); }
  58.     virtual ~ios();
  59.     operator void *() const
  60.         {return (void *)(!*this ? 0 : this); }
  61.     _Bool operator!() const
  62.         {return ((_State & (failbit|badbit)) != 0); }
  63.     ios& copyfmt(const ios&);
  64.     ostream *tie() const
  65.         {return (_Tiestr); }
  66.     ostream *tie(ostream *);
  67.     streambuf *rdbuf() const
  68.         {return (_Sb); }
  69.     streambuf *rdbuf(streambuf *);
  70.     iostate rdstate() const
  71.         {return (_State); }
  72.     void clear(iostate = goodbit);
  73.     void setstate(iostate _St)
  74.         {clear(_State | _St); }
  75.     _Bool good() const
  76.         {return (_State == goodbit); }
  77.     _Bool eof() const
  78.         {return (_State & eofbit); }
  79.     _Bool fail() const
  80.         {return (_State & (badbit | failbit)); }
  81.     _Bool bad() const
  82.         {return (_State & badbit); }
  83.     iostate exceptions() const
  84.         {return (_Except); }
  85.     void exceptions(iostate);
  86.     fmtflags flags() const
  87.         {return (_Fmtfl); }
  88.     fmtflags flags(fmtflags);
  89.     fmtflags setf(fmtflags);
  90.     fmtflags setf(fmtflags, fmtflags);
  91.     void unsetf(fmtflags);
  92.     int fill() const
  93.         {return (_Fillch); }
  94.     int fill(int);
  95.     int precision() const
  96.         {return (_Prec); }
  97.     int precision(int);
  98.     int width() const
  99.         {return (_Wide); }
  100.     int width(int);
  101.     static int xalloc()
  102.         {return (_Index++); }
  103.     long& iword(int _Idx)
  104.         {return (_Findarr(_Idx)._Lo); }
  105.     void *& pword(int _Idx)
  106.         {return (_Findarr(_Idx)._Vp); }
  107. #if _HAS_ENUM_OVERLOADING
  108.     void clear(io_state _St = 0)
  109.         {clear((iostate)_St); }
  110.     void setstate(io_state _St)
  111.         {setstate((iostate)_St); }
  112.     void exceptions(io_state _St)
  113.         {exceptions(iostate)_St); }
  114. #endif
  115. protected:
  116.     ios()
  117.         {init(0); }
  118.     ios(_Uninitialized)
  119.         {}
  120.     ios(const ios&);
  121.     ios& operator=(const ios&);
  122.     void init(streambuf *);
  123. private:
  124.     streambuf *_Sb;
  125.     ostream *_Tiestr;
  126.     iostate _State, _Except;
  127.     fmtflags _Fmtfl;
  128.     int _Prec, _Wide;
  129.     char _Fillch;
  130.     static int _Index;
  131.     _Iosarray *_Arr;
  132.     _Iosarray& _Findarr(int);
  133.     void _Tidy();
  134.     };
  135.         // manipulators
  136. ios& dec(ios&);
  137. ios& fixed(ios&);
  138. ios& hex(ios&);
  139. ios& internal(ios&);
  140. ios& left(ios&);
  141. ios& noshowbase(ios&);
  142. ios& noshowpoint(ios&);
  143. ios& noshowpos(ios&);
  144. ios& noskipws(ios&);
  145. ios& nouppercase(ios&);
  146. ios& oct(ios&);
  147. ios& right(ios&);
  148. ios& scientific(ios&);
  149. ios& showbase(ios&);
  150. ios& showpoint(ios&);
  151. ios& showpos(ios&);
  152. ios& skipws(ios&);
  153. ios& uppercase(ios&);
  154. #endif
  155.  
  156.  
  157.